﻿using StackExchange.Redis;
using WorldmeServer.Attributes;
using WorldmeServer.Utils;

namespace WorldmeServer.Services.Database
{
    /// <summary>
    /// redis 服务
    /// </summary>
    [SingletonRegistration]
    public class RedisService
    {
        int defaultDbIndex = 0;
        ConnectionMultiplexer redis;
        public RedisService()
        {
            redis = ConnectionMultiplexer.Connect(ConfigUtils.DatabaseConfig.Redis);
        }

        /// <summary>
        /// 基础数据库
        /// </summary>
        public IDatabase DefaultDb
        {
            get => redis.GetDatabase(defaultDbIndex);
        }
        public IDatabase GetDatabase(int index)
        {
            return redis.GetDatabase(index);
        }

    }
}
